﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Estimate.Common.DBFieldTypes;
using Estimate.Common.Entity;

namespace Estimate.Reports
{
   public class SaveEmptySemisToXML
    {

       public static void Save(DateTime beginDate, DateTime endDate, ForeSemiType realtype, ForeSpanType[] waterSpans, ForeSpanType[] tempSpans, ForeSendpointType[] sendpoints,List<ForeEntity> emptySemis,string fullFileName)
       {

           string strWaterSpans = "";
           for (int i = 0; i < waterSpans.Length; i++)
               if (strWaterSpans != "")
                   strWaterSpans += "," + waterSpans[i].ToString();
               else
                   strWaterSpans +=  waterSpans[i].ToString();

           string strTempSpans = "";
           for (int i = 0; i < tempSpans.Length; i++)
               if (strTempSpans != "")
                   strTempSpans += "," + tempSpans[i].ToString();
               else
                   strTempSpans +=  tempSpans[i].ToString();

           string strSendpoint = "";
           for (int i = 0; i < sendpoints.Length; i++)
               if (strSendpoint != "")
                   strSendpoint += "," + sendpoints[i].ToString();
               else
                   strSendpoint += sendpoints[i].ToString();
    

           string XmlString = "<ExecutionTime>" + DateTime.Now.ToString() + "</ExecutionTime>";
           XmlString += "<BeginDate>" + beginDate.ToString() + "</BeginDate>";
           XmlString += "<EndDate>" + endDate.ToString() + "</EndDate>";
           XmlString += "<ForeSemiType>" + realtype.ToString() + "</ForeSemiType>";
           XmlString += "<WaterSpans>" + strWaterSpans + "</WaterSpans>";
           XmlString += "<TempSpans>" + strSendpoint + "</TempSpans>";
           XmlString += "<ForeSendpointType>" + tempSpans + "</ForeSendpointType>";

           XmlString += "<EmptySemis>";
           foreach (ForeEntity entity in emptySemis)
           {
               XmlString += "<semi date='" + entity.Date.ToString()
                              + "' clock='" + entity.Clock.ToString()
                              + "' span='" + entity.Span.ToString()
                              + "' type='" + entity.Type.ToString()
                              + "' semitype='" + entity.Semitype.ToString()
                              + "' sendpoint='" + entity.Sendpoint.ToString()
                              + "' value='" + entity.Value + "'>";
           }

           XmlString += "</EmptySemis>";

           XmlDocument doc = new XmlDocument();
           doc.LoadXml(XmlString);
           doc.Save(fullFileName);
       }
    }
}
